﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace B.S.BasicData.Api.Read.Filters
{

    /// <summary>
    /// 全局异常过滤器类
    /// </summary>
    public class MyExceptionFilter : IExceptionFilter
    {
        private readonly ILogger<MyExceptionFilter> logger;

        public MyExceptionFilter(ILogger<MyExceptionFilter> logger)
        {
            this.logger = logger;
        }
        /// <summary>
        /// 全局异常过滤器的方法
        /// </summary>
        /// <param name="context"></param>
        public void OnException(ExceptionContext context)
        {
            logger.LogError("捕捉到全局异常:"+context.Exception.Message);
            context.ExceptionHandled = true;
        }
    }
}
